package com.gj.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gj.bean.CategoryBean;
import com.gj.bean.ContactsBean;
import com.gj.bean.UserBean;
import com.gj.dao.CategoryDao;
import com.gj.dao.ContactDao;
import com.gj.daoImp.CategoryDaoImp;
import com.gj.daoImp.ContactDaoImp;

/**
 * Servlet implementation class selectServlet
 */
@WebServlet("/selectServlet")
public class selectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public selectServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		/*HttpSession session=request.getSession();*/
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		/*UserBean user =(UserBean) session.getAttribute("user"); 
		ContactDao bookMng = new ContactDaoImp();
		CategoryDao categoryManage= new CategoryDaoImp();*/
		
		/*//管理员
		if(user.getUserRole()==0){
			 ArrayList<CategoryBean> category=categoryManage.GetCategoryInfo();
			 ArrayList<ContactsBean> list =bookMng.getContactInfo();  
			 request.setAttribute("Allcontacts", list); //联系人联系人列表
			 request.setAttribute("category", category);//分组
			request.getRequestDispatcher("jsp/mainPage.jsp"). forward(request, response);
			 //response.sendRedirect("jsp/mainPage.jsp");
		}
		//普通用户
		if(user.getUserRole()==1){ 
			 ArrayList<ContactsBean> list =bookMng.findContacts(user.getUserId());  //联系人联系人列表
			 ArrayList<CategoryBean> category=categoryManage.GetCategoryInfo();//分组
			 request.setAttribute("category", category);
			 request.setAttribute("Allcontacts", list);  
			request.getRequestDispatcher("mainPage.jsp"). forward(request, response);
			
		}*/
		response.sendRedirect("jsp/mainPage.jsp");
	}


}
